<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="第5章 变量与运算符, 湮灭星空,博客,Python,后端">
    <meta name="description" content="本章详细讲解变量的意义与七种运算符，并对每一种运算符的扩展做出详细的讲解。

5-1 什么是变量
变量命名的可读性要强！变量在 Python里就是一个名字。
Python的变量是不需要定义的。
a = 1

上述这种写法读作将1赋值给变量 ">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>第5章 变量与运算符 | 湮灭星空</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<link rel="alternate" href="/atom.xml" title="湮灭星空" type="application/atom+xml">
</head>

<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper head-container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">湮灭星空</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友链</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">湮灭星空</div>
        <div class="logo-desc">
            
            天下寥寥，苍生涂涂，诸子百家，唯我纵横
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友链
		</a>
          
        </li>
        
        
    </ul>
</div>

        </div>

        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/1.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        第5章 变量与运算符
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/python/">
                                <span class="chip bg-color">python</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E5%85%A5%E9%97%A8%E4%B8%8E%E8%BF%9B%E9%98%B6/" class="post-category">
                                入门与进阶
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2019-04-15
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2019-12-06
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    3.2k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    14 分
                </div>
                
				
                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
            
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>本章详细讲解变量的意义与七种运算符，并对每一种运算符的扩展做出详细的讲解。</p>
<a id="more"></a>
<h3 id="5-1-什么是变量"><a class="header-anchor" href="#5-1-什么是变量"></a>5-1 什么是变量</h3>
<p>变量命名的可读性要强！变量在 <code>Python</code>里就是一个名字。</p>
<p><strong><code>Python</code>的变量是不需要定义的。</strong></p>
<pre><code>a = 1
</code></pre>
<p>上述这种写法读作将1赋值给变量 a，并不是定义变量 a。</p>
<h3 id="5-2-变量的命名规则"><a class="header-anchor" href="#5-2-变量的命名规则"></a>5-2 变量的命名规则</h3>
<ul>
<li>变量命名只能使用<strong>数字</strong>、<strong>字母</strong>、<strong>下划线</strong>；</li>
<li><strong>首字符</strong>不能为数字；</li>
<li><strong>系统关键字</strong>不能用在变量名中；（系统关键字被称为保留关键字）</li>
<li><strong>变量名</strong>是区分大小写的；</li>
<li><code>Python</code>的变量是没有类型限制的，任何类型都可以赋值给变量，是 <code>Python</code> 作为动态语言的特性之一。</li>
</ul>
<p>有趣的现象：</p>
<pre><code class="language-python">In [150]: type = 1

In [151]: type
Out[151]: 1

In [152]: type(1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-152-a1aa052b5b77&gt; in &lt;module&gt;()
----&gt; 1 type(1)

TypeError: 'int' object is not callable
</code></pre>
<h3 id="5-3-值类型与引用类型"><a class="header-anchor" href="#5-3-值类型与引用类型"></a>5-3 值类型与引用类型</h3>
<h4 id="值类型-不可变"><a class="header-anchor" href="#值类型-不可变"></a>值类型（不可变）</h4>
<ul>
<li><code>int</code>、<code>str</code>、<code>tuple</code></li>
</ul>
<h4 id="引用类型-可变"><a class="header-anchor" href="#引用类型-可变"></a>引用类型（可变）</h4>
<ul>
<li>
<p><code>list</code>、<code>set</code>、<code>dict</code></p>
</li>
<li>
<p>现象一</p>
<pre><code class="language-python">In [141]: a = 1

In [142]: b = a

In [143]: a = 3

In [144]: b
Out[144]: 1
</code></pre>
<p>可以用下图解释上述过程：<img src="https://klause-blog-pictures.oss-cn-shanghai.aliyuncs.com/2019-05-14-144412.jpg" alt="image-20181023180558313"><img src="https://klause-blog-pictures.oss-cn-shanghai.aliyuncs.com/2019-05-14-144414.jpg" alt="image-20181023180805178"></p>
</li>
<li>
<p>现象二</p>
<pre><code class="language-python">In [145]: a = [1,2,3,4,5]

In [146]: b = a

In [147]: a[0] = '1'

In [148]: print(a)
['1', 2, 3, 4, 5]

In [149]: print(b)
['1', 2, 3, 4, 5]
</code></pre>
<p>可以用下图解释上述过程：</p>
<p><img src="https://klause-blog-pictures.oss-cn-shanghai.aliyuncs.com/2019-05-14-144415.jpg" alt="image-20181023181049824"><img src="https://klause-blog-pictures.oss-cn-shanghai.aliyuncs.com/2019-05-14-144417.jpg" alt="image-20181023181136675"></p>
</li>
<li>
<p>现象三</p>
<pre><code class="language-python">In [153]: a = 'hello'

In [154]: id(a)
Out[154]: 4364305832

In [155]: a = a + 'python'

In [156]: a
Out[156]: 'hellopython'

In [157]: id(a)
Out[157]: 4366761904
</code></pre>
<p>上述过程中两次 <code>a</code>的地址是不同的，可得出两个 <code>a</code>指向的是两个对象。</p>
</li>
</ul>
<h4 id="类型区别"><a class="header-anchor" href="#类型区别"></a>类型区别</h4>
<p>不可改变类型（值类型）在需要更改变量内容的时候会抛弃原对象，指向新的对象；</p>
<p>可变类型（引用类型）在更改变量内容的时候则是直接在原对象上修改。</p>
<h3 id="5-4-列表的可变与元组的不可变"><a class="header-anchor" href="#5-4-列表的可变与元组的不可变"></a>5-4 列表的可变与元组的不可变</h3>
<blockquote>
<p>小知识：</p>
<ul>
<li><code>id()</code>函数可以获取对象的内存地址；</li>
<li>计算机内存地址是用十六进制来表示的。</li>
</ul>
<pre><code class="language-python">In [1]: a = [1,2,3]

In [3]: id(a)
Out[3]: 4410830024

In [4]: hex(id(a))
Out[4]: '0x106e7ecc8'
</code></pre>
</blockquote>
<h4 id="列表的可变"><a class="header-anchor" href="#列表的可变"></a>列表的可变</h4>
<pre><code class="language-python">In [5]: a = [1,2,3]

In [6]: id(a)
Out[6]: 4410905608

In [7]: a[0] = '1'

In [8]: a
Out[8]: ['1', 2, 3]

In [9]: id(a)
Out[9]: 4410905608
</code></pre>
<p>如以上过程所演示，列表在改变内部元素的时候，<strong>内存地址</strong>是没有改变的，也就是说变量名指向的是同一个对象，这就是列表的可变性。</p>
<h4 id="元组的不可变"><a class="header-anchor" href="#元组的不可变"></a>元组的不可变</h4>
<pre><code class="language-python">In [10]: a = (1,2,3)

In [11]: a[0] = '1'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-11-752cfe243606&gt; in &lt;module&gt;()
----&gt; 1 a[0] = '1'

TypeError: 'tuple' object does not support item assignment
    
In [13]: a = (1,2,3)

In [14]: id(a)
Out[14]: 4379433360

In [15]: a = ('1',2,3)

In [16]: id(a)
Out[16]: 4381886936
</code></pre>
<p>上述过程表示元组的不可变。如果需要改变变量名必先抛弃原对象，重新指向新对象。</p>
<h4 id="不可变类型的重要意义"><a class="header-anchor" href="#不可变类型的重要意义"></a>不可变类型的重要意义</h4>
<p>编码最重要的是要保证代码的稳定性，简单代码变量的可变不可变意义不大，因为都是自己随手写的，别人不可能来调用或者来修改代码的，但是问题是在一个复杂的项目里，我们不可能一个人把一个很复杂的项目都写完，必须是很多人共同来写代码。如果是共同来写代码的话就涉及到<strong>代码的调用</strong>，涉及到代码的调用，这些不可能改变的类型是有优势的，因为别人尝试修改不可改变的类型马上就会报错，根本不会让它运行，这就避免了一些隐藏的错误。</p>
<p><strong>建议</strong>：能用不可改变的类型就用不可改变的类型。当然如果你需要动态改变组内部元素的话，还是用可变类型比较合适。</p>
<h3 id="5-5-运算符号"><a class="header-anchor" href="#5-5-运算符号"></a>5-5 运算符号</h3>
<p><img src="https://klause-blog-pictures.oss-cn-shanghai.aliyuncs.com/2019-05-14-144419.jpg" alt="image-20181024040629777"></p>
<h4 id="算术运算符"><a class="header-anchor" href="#算术运算符"></a>算术运算符</h4>
<p>运算符来源与数学，是对数字的运算，所以以下这些运算符被称为<strong>算术运算符</strong>。</p>
<h5 id="加法"><a class="header-anchor" href="#加法"></a>加法</h5>
<ul>
<li>
<p><code>+</code></p>
<pre><code class="language-python">In [17]: 'hello'+'world'
Out[17]: 'helloworld'
</code></pre>
</li>
</ul>
<h5 id="乘法"><a class="header-anchor" href="#乘法"></a>乘法</h5>
<ul>
<li>
<p><code>*</code></p>
<pre><code class="language-python">In [18]: 'hello'*3
Out[18]: 'hellohellohello'
</code></pre>
</li>
</ul>
<h5 id="除法"><a class="header-anchor" href="#除法"></a>除法</h5>
<ul>
<li>
<p><code>/</code></p>
<pre><code class="language-python">In [19]: 2/2
Out[19]: 1.0

In [20]: 5/2
Out[20]: 2.5
</code></pre>
</li>
</ul>
<h5 id="整除取整"><a class="header-anchor" href="#整除取整"></a>整除取整</h5>
<ul>
<li>
<p><code>//</code></p>
<pre><code class="language-python">In [21]: 5//2
Out[21]: 2
</code></pre>
</li>
</ul>
<h5 id="求余"><a class="header-anchor" href="#求余"></a>求余</h5>
<ul>
<li>
<p><code>%</code></p>
<pre><code class="language-python">In [23]: 5%2
Out[23]: 1

In [24]: 9%4
Out[24]: 1

In [25]: 10%4
Out[25]: 2
</code></pre>
</li>
</ul>
<h5 id="次方"><a class="header-anchor" href="#次方"></a>次方</h5>
<ul>
<li>
<p><code>**</code></p>
<pre><code class="language-python"># 2的2次方
In [26]: 2**2
Out[26]: 4

# 2的3次方
In [27]: 2**3
Out[27]: 8

# 2的4次方
In [28]: 2**4
Out[28]: 16

# 2的5次方
In [29]: 2**5
Out[29]: 32
</code></pre>
</li>
</ul>
<h3 id="5-6-赋值运算符"><a class="header-anchor" href="#5-6-赋值运算符"></a>5-6 赋值运算符</h3>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>=</td>
<td>简单的赋值运算符</td>
<td>c = a + b 将 a + b 的运算结果赋值为 c</td>
</tr>
<tr>
<td>+=</td>
<td>加法赋值运算符</td>
<td>c += a 等效于 c = c + a</td>
</tr>
<tr>
<td>-=</td>
<td>减法赋值运算符</td>
<td>c -= a 等效于 c = c - a</td>
</tr>
<tr>
<td>*=</td>
<td>乘法赋值运算符</td>
<td>c *= a 等效于 c = c * a</td>
</tr>
<tr>
<td>/=</td>
<td>除法赋值运算符</td>
<td>c /= a 等效于 c = c / a</td>
</tr>
<tr>
<td>%=</td>
<td>取模赋值运算符</td>
<td>c %= a 等效于 c = c % a</td>
</tr>
<tr>
<td>**=</td>
<td>幂赋值运算符</td>
<td>c **= a 等效于 c = c ** a</td>
</tr>
<tr>
<td>//=</td>
<td>取整除赋值运算符</td>
<td>c //= a 等效于 c = c // a</td>
</tr>
</tbody>
</table>
<h3 id="5-7-比较运算符"><a class="header-anchor" href="#5-7-比较运算符"></a>5-7 比较运算符</h3>
<p><strong>不同类型的对象不能进行比较！</strong></p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>==</td>
<td>等于 - 比较对象是否相等</td>
<td>(a == b) 返回 False。</td>
</tr>
<tr>
<td>!=</td>
<td>不等于 - 比较两个对象是否不相等</td>
<td>(a != b) 返回 true.</td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td>不等于 - 比较两个对象是否不相等</td>
<td>(a &lt;&gt; b) 返回 true。这个运算符类似 != 。</td>
</tr>
<tr>
<td>&gt;</td>
<td>大于 - 返回x是否大于y</td>
<td>(a &gt; b) 返回 False。</td>
</tr>
<tr>
<td>&lt;</td>
<td>小于 - 返回x是否小于y。所有比较运算符返回1表示真，返回0表示假。这分别与特殊的变量True和False等价。</td>
<td>(a &lt; b) 返回 true。</td>
</tr>
<tr>
<td>&gt;=</td>
<td>大于等于	- 返回x是否大于等于y。</td>
<td>(a &gt;= b) 返回 False。</td>
</tr>
<tr>
<td>&lt;=</td>
<td>小于等于 -	返回x是否小于等于y。</td>
<td>(a &lt;= b) 返回 true。</td>
</tr>
</tbody>
</table>
<h3 id="5-8-不只是数字才能做比较运算"><a class="header-anchor" href="#5-8-不只是数字才能做比较运算"></a>5-8 不只是数字才能做比较运算</h3>
<p>不仅<code>number</code>可以做比较运算，<code>list</code>、<code>str</code>、<code>tuple</code>、<code>dict</code>等都是可以做比较的。</p>
<ul>
<li>
<p>比较 <code>str</code></p>
<ul>
<li>
<p>单个字符串进行比较的时候，是将字符串转化为 ASCII 码之后在进行比较的</p>
<blockquote>
<p>字符串转换成 ASCII 码使用 <code>ord()</code>函数</p>
<pre><code class="language-python">In [65]: ord('a')
Out[65]: 97

In [66]: ord('b')
Out[66]: 98
</code></pre>
</blockquote>
</li>
<li>
<p>多个字符串进行比较的时候，是将两组字符串按照索引位顺序取出单个字符进行索引比较的，直至得出比较结果</p>
</li>
</ul>
<pre><code class="language-python">In [31]: 'a' &gt; 'b'
Out[31]: False
    
In [36]: 'abc' &lt; 'def'
Out[36]: True

In [37]: 'abc' &lt; 'aef'
Out[37]: True

In [38]: 'abc' &lt; 'aaf'
Out[38]: False

In [39]: 'abc' &lt; 'abf'
Out[39]: True

In [40]: 'abc' &lt; 'abb'
Out[40]: False
</code></pre>
</li>
<li>
<p>比较 <code>list</code>、<code>tuple</code>、<code>dict</code>与比较 <code>str</code>是一样的</p>
</li>
</ul>
<h3 id="5-9-逻辑运算符"><a class="header-anchor" href="#5-9-逻辑运算符"></a>5-9 逻辑运算符</h3>
<table>
<thead>
<tr>
<th>运算符</th>
<th>逻辑表达式</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>and</td>
<td>x and y</td>
<td>布尔&quot;与&quot; - 如果 x 为 False，x and y 返回 False，否则它返回 y 的计算值。</td>
<td>(a and b) 返回 20。</td>
</tr>
<tr>
<td>or</td>
<td>x or y</td>
<td>布尔&quot;或&quot;	- 如果 x 是非 0，它返回 x 的值，否则它返回 y 的计算值。</td>
<td>(a or b) 返回 10。</td>
</tr>
<tr>
<td>not</td>
<td>not x</td>
<td>布尔&quot;非&quot; - 如果 x 为 True，返回 False 。如果 x 为 False，它返回 True。</td>
<td>not(a and b) 返回 False</td>
</tr>
</tbody>
</table>
<p>有趣的现象之 <code>and</code>：</p>
<pre><code class="language-python"># 两个 True 对象，返回第二个 True 对象
In [44]: 1 and 3
Out[44]: 3

In [45]: 'a' and 'b'
Out[45]: 'b'

In [46]: 5 and 'a'
Out[46]: 'a'

# 两个 False 对象，返回第一个 False 对象
In [63]: 0 and []
Out[63]: 0

In [64]: [] and 0
Out[64]: []
    
# 一个 True 对象和一个 False 对象，返回 False 对象
In [67]: 1 and 0
Out[67]: 0

In [68]: 0 and 1
Out[68]: 0
</code></pre>
<p>有趣的现象之<code>or</code>：</p>
<pre><code class="language-python"># 两个 True 对象，返回第一个 True 对象
In [52]: 'a' or 'b'
Out[52]: 'a'
    
In [54]: 1 or 3
Out[54]: 1

# 一个 True 和一个 False 对象，返回 True 对象
In [53]: '' or 'b'
Out[53]: 'b'

In [55]: 0 or 3
Out[55]: 3
    
In [56]: 'a' or ''
Out[56]: 'a'

In [57]: 1 or o
Out[57]: 1
    
# 两个 False 对象，返回第二个 False 对象
In [61]: 0 or []
Out[61]: []

In [62]: [] or 0
Out[62]: 0
</code></pre>
<p>在 <code>number</code>、<code>str</code>、<code>list</code>、<code>tuple</code>、<code>dict</code>、<code>set</code>中：空被认为是 <code>False</code>，非空被认为是 <code>True</code>。</p>
<p>指的注意的现象：</p>
<pre><code class="language-python">In [59]: not ''
Out[59]: True

# '0'为非空字符串
In [60]: not '0'
Out[60]: False
</code></pre>
<h3 id="5-10-成员运算符"><a class="header-anchor" href="#5-10-成员运算符"></a>5-10 成员运算符</h3>
<p>特点：</p>
<ul>
<li>判断一个元素是否在一组元素里</li>
<li>返回值是 <code>bool</code></li>
</ul>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>in</td>
<td>如果在指定的序列中找到值返回 True，否则返回 False。</td>
<td>x 在 y 序列中 , 如果 x 在 y 序列中返回 True。</td>
</tr>
<tr>
<td>not in</td>
<td>如果在指定的序列中没有找到值返回 True，否则返回 False。</td>
<td>x 不在 y 序列中 , 如果 x 不在 y 序列中返回 True。</td>
</tr>
</tbody>
</table>
<p><code>number</code>、<code>str</code>、<code>list</code>、<code>tuple</code>、<code>set</code>、<code>dict</code>都支持成员运算符</p>
<pre><code class="language-python">In [69]: a = 1

# list
In [70]: a in [1,2,3,4]
Out[70]: True

In [71]: b = 6

In [72]: b in [1,2,3]
Out[72]: False

In [73]: b not in [1,2,3]
Out[73]: True

# str
In [75]: b in 'hello'
Out[75]: True

# tuple
In [76]: b not in (1,2,3,4)
Out[76]: True

# set
In [77]: b not in {1,2,3,4}
Out[77]: True
</code></pre>
<p>但是 <code>dict</code>的成员运算符比较特别，<code>dict</code>里的成员运算符是针对 <code>key:value</code>里的 <code>key</code>进行操作的。</p>
<pre><code class="language-python">In [78]: b = 'a'

In [79]: b in {'c':1}
Out[79]: False

In [80]: b = 1

In [81]: b in {'c':1}
Out[81]: False

In [82]: b = 'c'

In [83]: b in {'c':1}
Out[83]: True
</code></pre>
<h3 id="5-11-身份运算符"><a class="header-anchor" href="#5-11-身份运算符"></a>5-11 身份运算符</h3>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>is</td>
<td>is 是判断两个标识符是不是引用自一个对象</td>
<td><strong>x is y</strong>, 类似 <strong>id(x) == id(y)</strong> , 如果引用的是同一个对象则返回 True，否则返回 False</td>
</tr>
<tr>
<td>is not</td>
<td>is not 是判断两个标识符是不是引用自不同对象</td>
<td><strong>x is not y</strong> ， 类似 <strong>id(a) != id(b)</strong>。如果引用的不是同一个对象则返回结果 True，否则返回 False。</td>
</tr>
</tbody>
</table>
<pre><code class="language-python">In [84]: a = 1

In [85]: b = 1.0

In [86]: id(a)
Out[86]: 4368033776

In [87]: id(b)
Out[87]: 4410835472

# 关系运算符 == 只考虑取值是否相等
In [88]: a == b
Out[88]: True

In [89]: a is b
Out[89]: False
</code></pre>
<p>两个变量的取值相同并不代表身份也相同，身份可以用内存地址表示，因为它们的内存地址不同，所以它们的身份不同。</p>
<pre><code class="language-python"># set
In [92]: a = {1,2,3}

In [93]: b = {2,1,3}

In [94]: a == b
Out[94]: True

In [95]: a is b
Out[95]: False

In [96]: id(a)
Out[96]: 4386541640

In [97]: id(b)
Out[97]: 4386541864

# tuple
In [109]: c = (1,2,3)

In [110]: d = (2,1,3)

In [111]: c == d
Out[111]: False

In [112]: c is d
Out[112]: False

In [113]: id(c)
Out[113]: 4410495696

In [114]: id(d)
Out[114]: 4372745888
    
# list
In [115]: e = [1,2,3]

In [116]: f = [2,1,3]

In [117]: e == f
Out[117]: False

In [118]: e is f
Out[118]: False

In [119]: id(e)
Out[119]: 4409831880

In [120]: id(f)
Out[120]: 4410963080
</code></pre>
<h3 id="5-12-如何判断变量的值-身份与类型"><a class="header-anchor" href="#5-12-如何判断变量的值-身份与类型"></a>5-12 如何判断变量的值、身份与类型</h3>
<p>在 <code>Python</code>里，一切皆对象。对象的三个特征：</p>
<ul>
<li>值</li>
<li>身份</li>
<li>类型</li>
</ul>
<pre><code class="language-python">In [121]: a = 1

In [122]: b =22

# 值判断
In [123]: a == b
Out[123]: False

# 身份判断
In [124]: a is b
Out[124]: False

# 类型判断
In [125]: type(a) == type(b)
Out[125]: True
</code></pre>
<blockquote>
<p><code>Python</code>里有一个专门的函数来判断变量的类型：<code>isinstance()</code></p>
<pre><code class="language-python">In [126]: a = 'hello'

# 判断 a 是否是一个str
In [127]: isinstance(a, str)
Out[127]: True

# 判断 a 是否是一个 int
In [128]: isinstance(a, int)
Out[128]: False

# 判断 a 是不是后面元组里三种类型的任意一种
In [129]: isinstance(a, (int,str,float))
Out[129]: True
    
In [130]: isinstance(a, (int,float))
Out[130]: Fals
    
    
</code></pre>
<p><code>type()</code>与<code>isinstance()</code>的区别：</p>
<p><code>type</code>不能判断对象的子类是否属于某种类型的，但是 <code>isinstance</code>可以</p>
<pre><code class="language-python">class Color(object):
    pass

# 子类继承父类
class Red(Color):
    pass
 
print(type(Color()) == Color)
print(type(Red()) == Color)
print(isinstance(Red(),Color))
--------------------------------
运行结果：
True
False
True
</code></pre>
</blockquote>
<h3 id="5-13-位运算符"><a class="header-anchor" href="#5-13-位运算符"></a>5-13 位运算符</h3>
<pre><code class="language-python">In [134]: a = 2

In [135]: b =3

# a 按位与 b
In [136]: a &amp; b
Out[136]: 2
</code></pre>
<p>上述过程解释：</p>
<ol>
<li>将a转化为二进制数得到10，将b 转化为二进制数得到11；</li>
<li>分别将两个二进制数进行<strong>与</strong>操作，两个二进制数的第一位：0 and 1返回结果为0，两个二进制数第二位：1 and 1返回结果为1；</li>
<li>所以两个二进制数进行<strong>与</strong>操作之后，得到的是二进制数10；</li>
<li>最后将得到的二进制数10转化为十进制数2返回。</li>
</ol>
<blockquote>
<p>小知识：</p>
<p>异或：如果a、b两个值不相同，则异或结果为1。如果a、b两个值相同，异或结果为0。</p>
</blockquote>

<div id="gitalk-container"></div>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"><script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>

		<script>
		var gitalkConfig = {"clientID":"9eb5bc3ac1e1ff3ddac0","clientSecret":"4b7ae28042282281295075c2bf0c97ff1791cfeb","repo":"HexoBlogComments","owner":"Annihilater","admin":["Annihilater"],"distractionFreeMode":false};
	    gitalkConfig.id = md5(location.pathname);
		var gitalk = new Gitalk(gitalkConfig);
	    gitalk.render("gitalk-container");
	    </script>
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://www.klause.cn" rel="external nofollow noreferrer">湮灭星空</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://www.klause.cn/2019/04/15/python3-ru-men-yu-jin-jie-shi-pin-bi-ji/di-5-zhang-bian-liang-yu-yun-suan-fu/">https://www.klause.cn/2019/04/15/python3-ru-men-yu-jin-jie-shi-pin-bi-ji/di-5-zhang-bian-liang-yu-yun-suan-fu/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="https://www.klause.cn" target="_blank">湮灭星空</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/python/">
                                    <span class="chip bg-color">python</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
        </div>
    </div>

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2019/04/15/python3-ru-men-yu-jin-jie-shi-pin-bi-ji/di-3-zhang-li-jie-shi-me-shi-xie-dai-ma-yu-python-de-ji-ben-lei-xing/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/16.jpg" class="responsive-img" alt="第3章 理解什么是写代码与Python的基本类型">
                        
                        <span class="card-title">第3章 理解什么是写代码与Python的基本类型</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            第3章 理解什么是写代码与Python的基本类型
本章详细介绍了Python的基本类型，包括整形、浮点型；10、8、2、16进制数的意义和转换关系；布尔类型；字符串与字符串常见运算操作

3-1 什么是代码，什么是写代码

代码是现实世界事
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2019-04-15
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%85%A5%E9%97%A8%E4%B8%8E%E8%BF%9B%E9%98%B6/" class="post-category">
                                    入门与进阶
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/python/">
                        <span class="chip bg-color">python</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2019/04/15/python3-ru-men-yu-jin-jie-shi-pin-bi-ji/di-4-zhang-python-zhong-biao-shi-zu-de-gai-nian-yu-ding-yi/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/0.jpg" class="responsive-img" alt="第4章 Python中表示“组”的概念与定义">
                        
                        <span class="card-title">第4章 Python中表示“组”的概念与定义</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本章详细讲解了“组”的概念，以及在Python中用来表示“组”的一些类型，包括：元组、列表、集合和字典。

4-1 列表的定义
列表的定义是使用[]，中间元素使用，隔开
嵌套列表：
In [69]: type([[1, 2], [3, 'a
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2019-04-15
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%85%A5%E9%97%A8%E4%B8%8E%E8%BF%9B%E9%98%B6/" class="post-category">
                                    入门与进阶
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/python/">
                        <span class="chip bg-color">python</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>

    
<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>

    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h2, h3, h4, h5, h6'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4, h5, h6').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>



    <footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">年份</span>
            <a href="https://www.klause.cn" target="_blank">湮灭星空</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">199.2k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    window.setTimeout("siteTime()", 1000);
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2019";
                    var startMonth = "6";
                    var startDate = "28";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
            <span id="icp"><img src="/medias/icp.png" style="vertical-align: text-bottom;" />
                <a href="http://www.beian.miit.gov.cn" target="_blank">皖ICP备18005729号-1</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/Annihilater" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:yanmiexingkong@gmail.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>





    <a href="https://twitter.com/" class="tooltipped" target="_blank" data-tooltip="关注我的Twitter: https://twitter.com/" data-position="top" data-delay="50">
        <i class="fab fa-twitter"></i>
    </a>







    <a href="https://www.zhihu.com/" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://www.zhihu.com/" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>

    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Global site tag (gtag.js) - Google Analytics -->


    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
